package cn.tedu.charging.order.rabbit;

import cn.tedu.charging.order.config.RabbitMqConfig;
import cn.tedu.charging.order.pojo.dto.OrderMqDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Slf4j
@Component
public class RabbitMqProducer {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendOrder(OrderMqDTO orderMqDTO){
        rabbitTemplate.setConfirmCallback((correlationData, ack, cause) -> {
            if(ack){
                log.debug("生产者生成消息成功,correlationData:{},ack:{},cause:{}",correlationData,ack,cause);
            }else{
                log.debug("生产者生成消息失败,correlationData:{},ack:{},cause:{}",correlationData,ack,cause);
            }
        });

        rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_NAME,RabbitMqConfig.ROUTING_KEY,orderMqDTO);
    }
}
